// let a = new FormData();
// a.append(1, 2);
// a.append(
//     "file",
//     new File([123], "1.txt", {
//         type: "text/plain",
//     })
// );
// Fetch(url, {
//     method: "POST",
//     body: a,
// });
let domain = "http://localhost:6767/ajax"; //这个URL需要自定义
function Fetch(url, options) {
    if (!domain) {
        throw new Error("没有代理服务器的 URL");
    }
    let URL = "",
        OPTIONS = {};
    // formdata 上传
    if (options.body instanceof FormData) {
        options.body.append(
            "FETCHINFO",
            JSON.stringify({
                url,
                options,
            })
        );
        URL = domain;
        OPTIONS = {
            method: "POST",
            body: options.body,
        };
    } else {
        //string上传
        URL = domain + `?url=${url}&options=${JSON.stringify(options)}`;
        OPTIONS = {
            method: "GET",
        };
    }
    return new Promise((resolve, reject) => {
        fetch(URL, OPTIONS)
            .then((res) => res.blob())
            .then((res) => resolve(new FetchBlob(res)))
            .catch((err) => reject(err));
    });
}
class FetchBlob {
    constructor(blob) {
        this.blob = blob;
    }
    text() {
        return this.blob.text();
    }
    arrayBuffer() {
        return this.blob.arrayBuffer();
    }
    blob() {
        return this.blob;
    }
    json() {
        return JSON.stringify(this.blob.text());
    }
}
